.snippet-form-holder
  = form_for @snippet, url: url, html: { class: "form-horizontal snippet-form js-requires-input" } do |f|
    = form_errors(@snippet)

    .form-group
      = f.label :title, "标题", class: 'control-label'
      .col-sm-10
        = f.text_field :title, class: 'form-control', required: true, autofocus: true

    = render 'shared/visibility_level', f: f, visibility_level: visibility_level, can_change_visibility_level: true, form_model: @snippet

    .file-editor
      .form-group
        = f.label :file_name, "文件", class: 'control-label'
        .col-sm-10
          .file-holder.snippet
            .file-title
              = f.text_field :file_name, placeholder: "可选的文件名称以便增加代码高亮，比如 example.rb 显示 Ruby 代码。", class: 'form-control snippet-file-name'
            .file-content.code
              %pre#editor= @snippet.content
              = f.hidden_field :content, class: 'snippet-file-content'

    .form-actions
      - if @snippet.new_record?
        = f.submit '创建代码片段', class: "btn-create btn"
      - else
        = f.submit '保存修改', class: "btn-save btn"

      - if @snippet.project_id
        = link_to "取消", namespace_project_snippets_path(@project.namespace, @project), class: "btn btn-cancel"
      - else
        = link_to "取消", snippets_path(@project), class: "btn btn-cancel"

:javascript
  var editor = ace.edit("editor");
  $(".snippet-form-holder form").submit(function(){
    $(".snippet-file-content").val(editor.getValue());
  });
